FROM php:7.1.18-alpine

MAINTAINER albert <63851587@qq.com>

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories \
    && apk add --no-cache --virtual .build-deps \
    g++ \
    gcc \
    autoconf \
    make \
    libmcrypt-dev \
    gmp-dev \
    icu-dev \
    zlib-dev \
    musl \
    libc-dev \
    linux-headers \
    libaio-dev \
    && apk add --no-cache --virtual .deps \
    libcurl \
    ca-certificates \
    tzdata \
    nghttp2-dev \
    hiredis-dev \
    openssl-dev \
    pcre-dev \
    perl-dev \

    && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo 'Asia/Shanghai' > /etc/timezone \

    && pecl install redis && docker-php-ext-enable redis \
    && pecl install inotify && docker-php-ext-enable inotify && pecl clear-cache \
    && docker-php-ext-install pdo_mysql bcmath \

    && wget https://github.com/swoole/swoole-src/archive/v4.0.1.tar.gz -O swoole.tar.gz \
    && mkdir -p swoole \
    && tar -xf swoole.tar.gz -C swoole --strip-components=1 \
    && rm swoole.tar.gz \
    && ( \
        cd swoole \
        && phpize \
        && ./configure --enable-async-redis --enable-mysqlnd --enable-coroutine --enable-openssl --enable-http2 \
        && make -j$(nproc) \
        && make install \
    ) \
    && rm -r swoole \
    && docker-php-ext-enable swoole \

    && apk del .build-deps \
    && apk del --purge *-dev \
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && mkdir -p /data/wwwroot

#ADD . /data/wwwroot/yiisw
#
#WORKDIR /data/wwwroot/yiisw

#RUN curl -sS https://getcomposer.org/installer | php \
#    && mv composer.phar /usr/local/bin/composer \
#    && composer self-update --clean-backups \
#    && composer install --no-dev \
#           && composer dump-autoload -o \
#           && composer clearcache

EXPOSE 80

CMD ["php", "/data/wwwroot/yiisw", "swoole/websocket","start"]